package com.railway.servlet;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.railway.bean.Page;
import com.railway.bean.Train;
import com.railway.service.TrainService;
import com.railway.service.impl.TrainServiceImpl;
import com.railway.util.JSONUtil;

/**
 * Servlet implementation class ShowTrainServlet
 */
@WebServlet("/ShowTrainServlet.do")
public class ShowTrainServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
   
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("Utf-8");
	   	Map<String,String[]> map = request.getParameterMap();
	   	TrainService ts = new TrainServiceImpl();
	   	int pageNum = 1 ;
	   	int pageSize =5;
	   	
	   	if(request.getParameter("pageNum2") != null&& !"".equals(request.getParameter("pageNum2"))) {
	   		pageNum = Integer.parseInt(request.getParameter("pageNum2"));
	   	}
	   	
	 	if(request.getParameter("pageSize2") != null&& !"".equals(request.getParameter("pageSize2"))) {
	 		pageSize = Integer.parseInt(request.getParameter("pageSize2"));
	   	}
	 	Page<Train> page = ts.selectTrain(pageNum,pageSize);
	   	JSONUtil.responJSOn(response, page);
	}

}
